import ITask from "../types/ITask"
import ITaskData from "../types/ITaskData"
import localCache from "../../../utils/cache"
import { ElMessage } from "element-plus"
import { UNDERWAYTASKID, COMPLETEDTASKID } from "../constant/taskId"
import { taskName } from "../enum/taskName"

/**
 * 单个任务删除
 * @param task 要删除的任务
 * @param taskData 任务数据数组
 * @param taskType 任务类型
 */
export const taskDel = (task: ITask, taskData: ITaskData, taskType: string): boolean => {
    
  switch(taskType){
    case taskName.UNDERWAY:
      taskData.underwayTaskData = taskData.underwayTaskData.filter( item => item.id != task.id)
      break
    case taskName.COMPLETED:
      taskData.completedTaskData = taskData.completedTaskData.filter( item => item.id != task.id)
      break
  }
  localCache.clearCache()
  taskData.underwayTaskData.forEach(item => {
    localCache.setCache(UNDERWAYTASKID + item.id, item.title)
  })
  taskData.completedTaskData.forEach(item => {
    localCache.setCache(COMPLETEDTASKID + item.id, item.title)
  })
  
  ElMessage({
    showClose: true,
    message: '删除任务成功',
    type: 'success',
  })

  return true;
}
